#include <stdio.h>
#include "simpio.h"
#include "genlib.h"

bool isMeasurable(int target, int weights[], int nWeights);

int main() {
	int weights[10], nWeights = 0, i, sum = 0;

	printf("ALAL\n\nEnter weights, stop with -1\n\n");

	while (nWeights < 10) {
		printf("Enter weight number %d:\n", nWeights + 1);
		weights[nWeights] = GetInteger();
		if (weights[nWeights] == -1) break;
		sum += weights[nWeights];
		nWeights++;
	}
	
	for (i = 1; i <= sum; i++) {
		if (isMeasurable(i, weights, nWeights)) printf("%d is measurable.\n", i);
		else printf("%d is not measurable.\n", i);
	}
	
	return 0;
}

bool isMeasurable(int target, int weights[], int nWeights) {
	if (nWeights == -1) return FALSE;
	else {
		if (target == 0) return TRUE;
		if (isMeasurable(target, weights, nWeights-1)) return TRUE;
		if (isMeasurable(target + weights[nWeights-1], weights, nWeights-1)) return TRUE;
		if (isMeasurable(target - weights[nWeights-1], weights, nWeights-1)) return TRUE;	
	}
}